/**
 * @program: leetcode34
 * @author: JCM
 * @create: 2023-03-04 21:27
 * @description:
 **/
public class Main {
    public int[] searchRange1(int[] nums, int target) {
        int[] res = {-1,-1};
        if(nums.length < 1) return res;
        for(int i = 0; i < nums.length; i++) {
            if( nums[i] == target && i == 0 || nums[i] == target && nums[i-1] != target) {
                res[0] = i;
            }
            if(nums[i] == target && i+1 == nums.length || nums[i] == target && nums[i+1] != target) {
                res[1] = i;
            }
        }
        return res;
    }

    public int[] searchRange2(int[] nums, int target) {
        int[] ret = {-1,-1};
        for(int i = 0,j = nums.length-1;i<=j;) {
            if(nums[i] == target) {
                if(ret[0] == -1) {
                    ret[0] = i;
                }
            }else {
                i++;
            }
            if(nums[j] == target) {
                if(ret[1] == -1) {
                    ret[1] = j;
                }
            }else {
                j--;
            }
            if(ret[0] != -1 && ret[1] != -1) break;
        }
        return ret;
    }
}
